package com.turbo.cloud.contract.web.webservice;

import com.turbo.cloud.contract.web.logic.SceneLogic;
import com.turbo.cloud.contract.web.model.scene.CtContractSceneQO;
import com.turbo.cloud.contract.web.model.scene.CtContractSceneDO;
import com.turbo.cloud.contract.web.model.scene.CtContractSceneVO;
import com.turbo.cloud.core.api.R;
import com.turbo.cloud.core.api.Result;
import com.turbo.cloud.core.base.PageQuery;
import com.turbo.cloud.core.validated.InsertValidated;
import com.turbo.cloud.core.validated.UpdateValidated;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 合同场景表 前端控制器
 * </p>
 *
 * @author zhangluning
 * @since 2023-11-23
 */
@Slf4j
@RequiredArgsConstructor
@RestController
public class CtContractSceneController {

    final SceneLogic sceneLogic;

    /**
     * 模糊查询合同模板分页列表
     *
     * @param pageQuery 分页查询实体
     * @return Page
     */
    @PostMapping(name = "模糊查询用户分页列表", value = "/webservice/scene/queryContractScenePage")
    public Result<PageQuery<CtContractSceneVO>> queryContractScenePage(@RequestBody PageQuery<CtContractSceneQO> pageQuery) {
        PageQuery<CtContractSceneVO> result = sceneLogic.queryContractScenePage(pageQuery);
        return R.result(result);
    }

    /**
     * 新增合同模板
     *
     * @param ctContractSceneDO 实体
     * @return
     */
    @PostMapping(name = "新增合同模板", value = "/webservice/scene/createContractScene")
    public Result<Boolean> createRole(@RequestBody @Validated(InsertValidated.class) CtContractSceneDO ctContractSceneDO) {
        boolean result = sceneLogic.createContractScene(ctContractSceneDO);
        return R.result(result);
    }

    /**
     * 修改合同模板
     *
     * @param ctContractSceneDO 实体
     * @return
     */
    @PostMapping(name = "修改合同模板", value = "/webservice/scene/modifyContractScene")
    public Result<Boolean> modifyRole(@RequestBody @Validated(UpdateValidated.class) CtContractSceneDO ctContractSceneDO) {
        boolean result = sceneLogic.modifyContractScene(ctContractSceneDO);
        return R.result(result);
    }

    /**
     * 开启、关闭合同模板有效状态
     *
     * @param id 合同模板ID
     * @return
     */
    @GetMapping(name = "开启、关闭合同模板有效状态", value = "/webservice/scene/enabledContractSceneStateById")
    public Result<Boolean> enabledContractSceneStateById(@RequestParam @NotBlank(message = "合同模板ID不能为空") String id) {
        boolean result = sceneLogic.enabledContractSceneStateById(id);
        return R.result(result);
    }

    /**
     * 删除合同模板
     *
     * @param id 合同模板ID
     * @return
     */
    @GetMapping(name = "删除合同模板", value = "/webservice/scene/removeContractSceneById")
    public Result<Boolean> removeContractSceneById(@RequestParam @NotBlank(message = "合同模板ID不能为空") String id) {
        boolean result = sceneLogic.removeContractSceneById(id);
        return R.result(result);
    }
}
